package com.tju.ffmpeg;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;

public class Shopee {

    @Test
    public void test() {
//        String res = findLongestSubstr("ssssssssssssssshhhhopeeeeeeee");
//        System.out.println(res);
//        System.out.println('l'-'L');

        int res=maxIntValue(new int[]{4,2,3});
        System.out.println(res);

    }


    public String findLongestSubstr(String str) {
        // write code here
        if(str.length()<=1) return str;
        char[] chars = str.toCharArray();
        int resLeft=0, resRight=0;
        int left=0, right=0;
        while(right<chars.length) {
            while(right<chars.length && (chars[right]==chars[left] || chars[right]==chars[left]+32 || chars[right]==chars[left]-32)) {
                right++;
            }
            if(right-left>resRight-resLeft) {
                resLeft = left;
                resRight = right;
            }
            left = right;
        }
        return str.substring(resLeft, resRight);
    }

    public int maxIntValue(int[] arrs) {
        // write code here
        if(arrs.length==1) return arrs[0];
        Arrays.sort(arrs);
        int result = 0;
        for(int i=arrs.length-1; i>=0; i--) {
            result = result*10 + arrs[i];
        }
        return result;
    }


    public boolean IsSubtree(TreeNode tree1, TreeNode tree2) {
        // write code here
        if(tree2==null) return false;
        return isSubTree(tree1, tree2);
    }

    private boolean isSubTree(TreeNode tree1, TreeNode tree2) {
        if(tree2==null) return true;
        if(tree1==null) return false;
        boolean res = false;
        if(tree1.val==tree2.val) {
            res = isSubTree(tree1.left, tree2.left) && isSubTree(tree1.right, tree2.right);
        }
        if(res) return true;
        return isSubTree(tree1.left, tree2) || isSubTree(tree1.right, tree2);
    }
}

class TreeNode {
    int val = 0;
   TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
      this.val = val;
    }
}
